home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / gxdevice.h < prev    next >
C/C++ Source or Header  |  1993-05-26  |  10KB  |  257 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gxdevice.h */
  20. /* Device description structure for Ghostscript library */
  21. #include "gsmatrix.h"
  22. #include "gsxfont.h"
  23. #include "gxbitmap.h"
  24.  
  25. /* See drivers.doc for documentation of the driver interface. */
  26.  
  27. /* Define the type for device color indices. */
  28. typedef unsigned long gx_color_index;
  29. /* Define the 'transparent' color index. */
  30. #define gx_no_color_index_value (-1)    /* no cast -> can be used in #if */
  31. #define gx_no_color_index ((gx_color_index)gx_no_color_index_value)
  32.  
  33. /* Define the type for gray or RGB values at the driver interface. */
  34. typedef unsigned short gx_color_value;
  35. /* We might use less than the full range someday. */
  36. /* ...bits must lie between 8 and 16. */
  37. #define gx_color_value_bits (sizeof(gx_color_value) * 8)
  38. #define gx_max_color_value ((gx_color_value)((1L << gx_color_value_bits) - 1))
  39. #define gx_color_value_to_byte(cv)\
  40.   ((cv) >> (gx_color_value_bits - 8))
  41. #define gx_color_value_from_byte(cb)\
  42.   (((cb) << (gx_color_value_bits - 8)) + ((cb) >> (16 - gx_color_value_bits)))
  43.  
  44. /* Define the structure for device color capabilities. */
  45. typedef struct gx_device_color_info_s {
  46.     int num_components;        /* 1 = gray only, 3 = RGB, */
  47.                     /* 4 = CMYK (not supported) */
  48.     int depth;            /* # of bits per pixel */
  49.     gx_color_value max_gray;    /* # of distinct gray levels -1 */
  50.     gx_color_value max_rgb;        /* # of distinct color levels -1 */
  51.                     /* (only relevant if num_comp. > 1) */
  52.     gx_color_value dither_gray;    /* size of gray ramp for dithering */
  53.     gx_color_value dither_rgb;    /* size of color cube ditto */
  54.                     /* (only relevant if num_comp. > 1) */
  55. } gx_device_color_info;
  56. #define dci_black_and_white { 1, 1, 1, 0, 2, 0 }
  57. #define dci_color(depth,maxv,dither) { 3, depth, maxv, maxv, dither, dither }
  58. #define gx_device_has_color(dev) ((dev)->color_info.num_components > 1)
  59.  
  60. /* Structure for device procedures */
  61. typedef struct gx_device_procs_s gx_device_procs;
  62.  
  63. /* Structure for generic device description */
  64. #define gx_device_common\
  65.     int params_size;        /* size of this structure */\
  66.     gx_device_procs *procs;\
  67.     const char *dname;        /* the device name */\
  68.     int width;            /* width in pixels */\
  69.     int height;            /* height in pixels */\
  70.     float x_pixels_per_inch;    /* x density */\
  71.     float y_pixels_per_inch;    /* y density */\
  72.     float l_margin, b_margin, r_margin, t_margin;    /* margins around */\
  73.                     /* imageable area, in inches */\
  74.     gx_device_color_info color_info;    /* color information */\
  75.     int is_open            /* true if device has been opened */
  76. #define no_margins 0, 0, 0, 0
  77. /* A generic device */
  78. struct gx_device_s {
  79.     gx_device_common;
  80. };
  81. #ifndef gx_device_DEFINED
  82. #  define gx_device_DEFINED
  83. typedef struct gx_device_s gx_device;
  84. #endif
  85. /* A null device.  This is used to temporarily disable output. */
  86. typedef struct gx_device_null_s {
  87.     gx_device_common;
  88.     gx_device *target;        /* (used for xfont procs) */
  89. } gx_device_null;
  90. extern gx_device_null gs_null_device;
  91.  
  92. /* Define an opaque type for property lists. */
  93. #ifndef gs_prop_item_DEFINED
  94. #  define gs_prop_item_DEFINED
  95. typedef struct gs_prop_item_s gs_prop_item;
  96. #endif
  97.  
  98. /* Definition of device procedures. */
  99. /* Note that the gx_device * argument is not declared const, */
  100. /* because many drivers maintain dynamic state in the device structure. */
  101.  
  102. struct gx_device_procs_s {
  103.  
  104. #define dev_proc_open_device(proc)\
  105.   int proc(P1(gx_device *dev))
  106.     dev_proc_open_device((*open_device));
  107.  
  108. #define dev_proc_get_initial_matrix(proc)\
  109.   void proc(P2(gx_device *dev, gs_matrix *pmat))
  110.     dev_proc_get_initial_matrix((*get_initial_matrix));
  111.  
  112. #define dev_proc_sync_output(proc)\
  113.   int proc(P1(gx_device *dev))
  114.     dev_proc_sync_output((*sync_output));
  115.  
  116. #define dev_proc_output_page(proc)\
  117.   int proc(P3(gx_device *dev, int num_copies, int flush))
  118.     dev_proc_output_page((*output_page));
  119.  
  120. #define dev_proc_close_device(proc)\
  121.   int proc(P1(gx_device *dev))
  122.     dev_proc_close_device((*close_device));
  123.  
  124. #define dev_proc_map_rgb_color(proc)\
  125.   gx_color_index proc(P4(gx_device *dev,\
  126.     gx_color_value red, gx_color_value green, gx_color_value blue))
  127.     dev_proc_map_rgb_color((*map_rgb_color));
  128.  
  129. #define dev_proc_map_color_rgb(proc)\
  130.   int proc(P3(gx_device *dev,\
  131.     gx_color_index color, gx_color_value rgb[3]))
  132.     dev_proc_map_color_rgb((*map_color_rgb));
  133.  
  134. #define dev_proc_fill_rectangle(proc)\
  135.   int proc(P6(gx_device *dev,\
  136.     int x, int y, int width, int height, gx_color_index color))
  137.     dev_proc_fill_rectangle((*fill_rectangle));
  138.  
  139. #define dev_proc_tile_rectangle(proc)\
  140.   int proc(P10(gx_device *dev,\
  141.     const gx_bitmap *tile, int x, int y, int width, int height,\
  142.     gx_color_index color0, gx_color_index color1,\
  143.     int phase_x, int phase_y))
  144.     dev_proc_tile_rectangle((*tile_rectangle));
  145.  
  146. #define dev_proc_copy_mono(proc)\
  147.   int proc(P11(gx_device *dev,\
  148.     const unsigned char *data, int data_x, int raster, gx_bitmap_id id,\
  149.     int x, int y, int width, int height,\
  150.     gx_color_index color0, gx_color_index color1))
  151.     dev_proc_copy_mono((*copy_mono));
  152.  
  153. #define dev_proc_copy_color(proc)\
  154.   int proc(P9(gx_device *dev,\
  155.     const unsigned char *data, int data_x, int raster, gx_bitmap_id id,\
  156.     int x, int y, int width, int height))
  157.     dev_proc_copy_color((*copy_color));
  158.  
  159. #define dev_proc_draw_line(proc)\
  160.   int proc(P6(gx_device *dev,\
  161.     int x0, int y0, int x1, int y1, gx_color_index color))
  162.     dev_proc_draw_line((*draw_line));
  163.  
  164.         /* Added in release 2.4 */
  165.  
  166. #define dev_proc_get_bits(proc)\
  167.   int proc(P4(gx_device *dev,\
  168.     int y, unsigned char *data, unsigned char **actual_data))
  169.     dev_proc_get_bits((*get_bits));
  170.  
  171. #define dev_proc_get_props(proc)\
  172.   int proc(P2(gx_device *dev, gs_prop_item *plist))
  173.     dev_proc_get_props((*get_props));
  174.     
  175. #define dev_proc_put_props(proc)\
  176.   int proc(P3(gx_device *dev, gs_prop_item *plist, int count))
  177.     dev_proc_put_props((*put_props));
  178.  
  179.         /* Added in release 2.6 */
  180.  
  181. #define dev_proc_map_cmyk_color(proc)\
  182.   gx_color_index proc(P5(gx_device *dev,\
  183.     gx_color_value cyan, gx_color_value magenta, gx_color_value yellow,\
  184.     gx_color_value black))
  185.     dev_proc_map_cmyk_color((*map_cmyk_color));
  186.     
  187. #define dev_proc_get_xfont_procs(proc)\
  188.   gx_xfont_procs *proc(P1(gx_device *dev))
  189.     dev_proc_get_xfont_procs((*get_xfont_procs));
  190.  
  191.         /* Added in release 2.6.1 */
  192.  
  193. #define dev_proc_get_xfont_device(proc)\
  194.   gx_device *proc(P1(gx_device *dev))
  195.     dev_proc_get_xfont_device((*get_xfont_device));
  196.  
  197. };
  198.  
  199. /* Calculate the raster (number of bytes in a scan line), */
  200. /* with byte or word padding. */
  201. extern unsigned int gx_device_raster(P2(const gx_device *dev,
  202.   int pad_to_word));
  203.  
  204. /* Adjust the resolution for devices that only have a fixed set of */
  205. /* geometries, so that the apparent size in inches remains constant. */
  206. /* If fit=1, the resolution is adjusted so that the entire image fits; */
  207. /* if fit=0, one dimension fits, but the other one is clipped. */
  208. extern int gx_device_adjust_resolution(P4(gx_device *dev, int actual_width, int actual_height, int fit));
  209.  
  210. /*
  211.  * Macros to help the drawing procedures clip coordinates to
  212.  * fit into the drawing region.  Note that these may modify
  213.  * x, y, w, h, data, data_x, and id.
  214.  */
  215.  
  216. /* Macro for fill_rectangle and tile_rectangle. */
  217. #define fit_fill(dev, x, y, w, h)\
  218.     if ( (x | y) < 0 )\
  219.     {    if ( x < 0 ) w += x, x = 0;\
  220.         if ( y < 0 ) h += y, y = 0;\
  221.     }\
  222.     if ( x > dev->width - w ) w = dev->width - x;\
  223.     if ( y > dev->height - h ) h = dev->height - y;\
  224.     if ( w <= 0 || h <= 0 ) return 0
  225.  
  226. /* Macro for copy_mono and copy_color. */
  227. #define fit_copy(dev, data, data_x, raster, id, x, y, w, h)\
  228.     if ( (x | y) < 0 )\
  229.     {    if ( x < 0 ) w += x, data_x -= x, x = 0;\
  230.         if ( y < 0 ) h += y, data -= y * raster, id = gx_no_bitmap_id, y = 0;\
  231.     }\
  232.     if ( x > dev->width - w ) w = dev->width - x;\
  233.     if ( y > dev->height - h ) h = dev->height - y;\
  234.     if ( w <= 0 || h <= 0 ) return 0
  235.  
  236. /* Default implementations of optional procedures */
  237. dev_proc_open_device(gx_default_open_device);
  238. dev_proc_get_initial_matrix(gx_default_get_initial_matrix);
  239. dev_proc_sync_output(gx_default_sync_output);
  240. dev_proc_output_page(gx_default_output_page);
  241. dev_proc_close_device(gx_default_close_device);
  242. dev_proc_map_rgb_color(gx_default_map_rgb_color);
  243. dev_proc_map_color_rgb(gx_default_map_color_rgb);
  244. dev_proc_tile_rectangle(gx_default_tile_rectangle);
  245. dev_proc_copy_color(gx_default_copy_color);
  246. dev_proc_draw_line(gx_default_draw_line);
  247. dev_proc_get_bits(gx_default_get_bits);
  248. dev_proc_get_props(gx_default_get_props);
  249. dev_proc_put_props(gx_default_put_props);
  250. dev_proc_map_cmyk_color(gx_default_map_cmyk_color);
  251. dev_proc_get_xfont_procs(gx_default_get_xfont_procs);
  252. dev_proc_get_xfont_device(gx_default_get_xfont_device);
  253.  
  254. /* Fill in defaulted procedures in a device procedure record. */
  255. extern void gx_device_complete_procs(P1(gx_device *));
  256. extern void gx_device_procs_complete(P1(gx_device_procs *));
  257.